package com.ulook.lookplanet.service;

import com.ulook.lookplanet.bean.TUser;
import com.ulook.lookplanet.mapper.LoginMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 登陆服务
 */
@Service
public class LoginService {

    @Autowired
    private LoginMapper loginMapper;

    /**
     * 登陆
     */
    public TUser login(TUser user){
        return loginMapper.getUser(user);
    }

    /**
     * 注册
     */
    @Transactional
    public TUser register(TUser user){
        // 检查邮箱是否被注册
        int check = loginMapper.checkEmail(user.getEmail());
        if(check > 0){
            return null;
        }
        // 添加新用户
        loginMapper.addUser(user);
        // 登陆新用户
        return loginMapper.getUser(user);
    }
}
